package com.java110.mall.user.cmd.userAddress;

import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.CmdContextUtils;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.dto.user.UserAddressDto;
import com.java110.mall.user.bmo.userAddress.IGetUserAddressBMO;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;

@Java110Cmd(serviceCode = "userAddress.queryUserAddress")
public class QueryUserAddressCmd extends Cmd {

    @Autowired
    private IGetUserAddressBMO getUserAddressBMOImpl;
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        super.validatePageInfo(reqJson);
    }

    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        String userId = CmdContextUtils.getUserId(context);
        UserAddressDto userAddressDto = BeanConvertUtil.covertBean(reqJson, UserAddressDto.class);

        userAddressDto.setUserId(userId);
        ResponseEntity<String> responseEntity =  getUserAddressBMOImpl.get(userAddressDto);
        context.setResponseEntity(responseEntity);
    }
}
